#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import random

class DivinationAgent:
    """占卜智能体：负责卦象生成"""
    def __init__(self):
        self.methods = {
            'coin': self._coin_method,
            'yarrow': self._yarrow_method
        }
    
    def _coin_method(self):
        """三枚硬币占卜法"""
        return sum(random.choice([2, 3]) for _ in range(3))  # 2为阴，3为阳
    
    def _yarrow_method(self):
        """蓍草占卜法（简化版）"""
        return random.choice([6, 7, 8, 9])  # 6-老阴,7-少阳,8-少阴,9-老阳
    
    def generate_hexagram(self, method='coin'):
        """生成卦象"""
        if method not in self.methods:
            raise ValueError("Invalid divination method")
        
        lines = []
        for _ in range(6):
            lines.append(self.methods[method]())
        
        # 计算本卦和变爻
        primary = []
        changing = []
        for line in lines:
            if line == 6:  # 老阴
                primary.append(8)  # 少阴
                changing.append(True)
            elif line == 9:  # 老阳
                primary.append(7)  # 少阳
                changing.append(True)
            else:
                primary.append(line)
                changing.append(False)
        
        return primary, changing